home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Resources / System / BoingBag1 / Contributions / InstallerNG / GUI-API / example / libstuff.c < prev   
C/C++ Source or Header  |  1999-11-01  |  22KB  |  678 lines

  1.  
  2. #include "installergui_base.h"
  3. #include "includes.h"
  4. #include "installergui_data.h"
  5.  
  6. #include <string.h>
  7.  
  8. /********************************************************************
  9.  *
  10.  *  DESCRIPTION
  11.  *
  12.  *  - private for initialisation and cleanup code for the
  13.  *    library; you may also declare library-global data here
  14.  *    (note that libcode must be re-entrant!)
  15.  *  - several support functions
  16.  *
  17.  */
  18.  
  19. /********************************************************************
  20.  *
  21.  *  STATIC
  22.  *
  23.  */
  24.  
  25. /********************************************************************
  26.  *
  27.  *  EXTERN
  28.  *
  29.  */
  30.  
  31. /********************************************************************
  32.  *
  33.  *  PUBLIC
  34.  *
  35.  */
  36.  
  37. struct Library *MUIMasterBase = NULL;
  38.  
  39. /********************************************************************
  40.  *
  41.  *  CODE
  42.  *
  43.  */
  44.  
  45. /********************************************************************/
  46.  
  47. /********************************************************************/
  48.  
  49. void guistuff_SetBackButton(APTR application, BOOL setit)
  50. {
  51.   // handle the BACK button and note, wheter we are in "back"-mode or not
  52.   struct Application *app = (struct Application *) application;
  53.  
  54.   if (setit) { igui_NameCancel(app, app->app_Texts[BUTTON_BACK]); }
  55.   else       { igui_NameCancel(app, (char *) app->app_GlobalEnv[GENV_ABORT_BUTTON]); }
  56.  
  57.   app->app_BACK_Mode = setit;
  58. }
  59.  
  60. /********************************************************************/
  61.  
  62. void guistuff_SleepApp(APTR application)
  63. {
  64.   set(((struct Application *) application)->app_MainWindow, MUIA_Window_Sleep, TRUE);
  65.   set(((struct Application *) application)->app_HelpWindow, MUIA_Window_Sleep, TRUE);
  66.   set(((struct Application *) application)->app_MkdirWindow, MUIA_Window_Sleep, TRUE);
  67.   set(((struct Application *) application)->app_GaugeWindow, MUIA_Window_Sleep, TRUE);
  68.   set(((struct Application *) application)->app_AboutWindow, MUIA_Window_Sleep, TRUE);
  69. }
  70.  
  71. /********************************************************************/
  72.  
  73. void guistuff_WakeApp(APTR application)
  74. {
  75.   guistuff_WakeWindow(((struct Application *) application)->app_MainWindow);
  76.   guistuff_WakeWindow(((struct Application *) application)->app_HelpWindow);
  77.   guistuff_WakeWindow(((struct Application *) application)->app_MkdirWindow);
  78.   guistuff_WakeWindow(((struct Application *) application)->app_GaugeWindow);
  79.   guistuff_WakeWindow(((struct Application *) application)->app_AboutWindow);
  80. }
  81.  
  82. /********************************************************************/
  83.  
  84. void guistuff_WakeWindow(APTR window)
  85. {
  86.   ULONG sleeps;
  87.  
  88.   do
  89.   {
  90.     set(window, MUIA_Window_Sleep, FALSE);
  91.     GetAttr(MUIA_Window_Sleep, window, &sleeps);
  92.   }
  93.   while (sleeps);
  94. }
  95.  
  96. /********************************************************************/
  97.  
  98. // this helps to center the a text within a floattext object!
  99. // (suggested by Jens Langner)
  100. char *guistuff_CenterText(char *text)
  101. {
  102.   char *centtext;
  103.   int i, numlf;
  104.  
  105.   for (i=0, numlf=0; text[i]; i++, numlf += (text[i]=='\n')?1:0);
  106.  
  107.   centtext = sav_AllocVec(strlen(text) + (numlf*4) + 1, MEMF_ANY|MEMF_CLEAR);
  108.   if (!centtext) { return(text); }
  109.  
  110.   for(i=0; strlen(text) > 0; text += i)
  111.   {
  112.     char *poschr = strstr(text, "\n");
  113.  
  114.     i = 1 + strlen(text) - (poschr ? strlen(poschr) : 1);
  115.     strcat(centtext, "\33c");
  116.     strncat(centtext, text, i);
  117.   }
  118.  
  119.   return(centtext);
  120. }
  121.  
  122. /********************************************************************/
  123.  
  124. // create a radio-button
  125. APTR guistuff_InitRadio(BOOL selected, BOOL disabled)
  126. {
  127.   #ifdef DEBUG
  128.   DEBUG_MAKRO
  129.   #endif
  130.  
  131.   return(ImageObject,
  132.            MUIA_Image_Spec, 16,
  133.            MUIA_InputMode, MUIV_InputMode_Immediate,
  134.            MUIA_Selected, selected,
  135.            MUIA_Disabled, disabled,
  136.          End);
  137. }
  138.  
  139. /********************************************************************/
  140.  
  141. // handle a gui event: return TRUE if the gui has to wait, FALSE otherwise
  142. BOOL guistuff_HandleGUIEvent(APTR application, long event)
  143. {
  144.   #ifdef DEBUG
  145.   DEBUG_MAKRO
  146.   #endif
  147.  
  148.   {
  149.     // set app->app_Quit to TRUE when quit, otherwise do "nothing"
  150.     struct Application *app = application;
  151.  
  152.     switch (event)
  153.     {
  154.       // der proceed button
  155.       case GUIEVENT_BACK:
  156.       case GUIEVENT_PROCEED: { return (FALSE); }
  157.  
  158.       // abort button
  159.       // (special handling in special cases: SWING mode: if set, then
  160.       // the "cancel" button is quiet!)
  161.       case GUIEVENT_ABORT:
  162.       {
  163.         if (app->app_SWING_Mode) { return (FALSE); }
  164.       }
  165.  
  166.       // user wants to quit
  167.       case GUIEVENT_QUIT:
  168.       {
  169.         // do not prompt the user within TRAP handling
  170.         if (app->app_TRAP_Mode) { return (FALSE); }
  171.  
  172.         //
  173.         else if (igui_Request(app, NULL, app->app_Texts[YES_NO], app->app_Texts[REALLY_QUIT], NULL))
  174.         {
  175.           // if we are in SWING mode, we have to reset the SWING mode first
  176.           igui_SWING_Mode(app, FALSE);
  177.  
  178.           app->app_Quit = TRUE;
  179.           return (FALSE);
  180.         }
  181.       }
  182.     }
  183.  
  184.     // ansonsten weiter warten!
  185.     return (TRUE);
  186.   }
  187. }
  188.  
  189. /********************************************************************/
  190.  
  191. // change tho panels of the installer gui
  192. BOOL guistuff_NewContent(APTR application, APTR newobject)
  193. {
  194.   #ifdef DEBUG
  195.   DEBUG_MAKRO
  196.   #endif
  197.  
  198.   {
  199.     struct Application *app = (struct Application *) application;
  200.  
  201.     if (!newobject)
  202.     {
  203.       app->app_Error = GUIERROR_NO_GUI_OBJECT;
  204.       return(FALSE);
  205.     }
  206.  
  207.     if(DoMethod(app->app_MainRoot, MUIM_Group_InitChange))
  208.     {
  209.       // remove old object. Add new one.
  210.       DoMethod(app->app_MainRoot, OM_REMMEMBER, app->app_CurrentObject);
  211.       DoMethod(app->app_MainRoot, OM_ADDMEMBER, newobject);
  212.  
  213.       // dispose old object
  214.       DisposeObject(app->app_CurrentObject);
  215.  
  216.       // new object gets the current one
  217.       app->app_CurrentObject = newobject;
  218.  
  219.       // let the group relayout itself.
  220.       DoMethod(app->app_MainRoot, MUIM_Group_ExitChange);
  221.     }
  222.     return(TRUE);
  223.   }
  224. }
  225.  
  226. /********************************************************************/
  227.  
  228. APTR guistuff_InitSimpleText(char *text)
  229. {
  230.   #ifdef DEBUG
  231.   DEBUG_MAKRO
  232.   #endif
  233.  
  234.   /*
  235.   return(ListviewObject,
  236.            MUIA_Listview_Input, FALSE,
  237.            //MUIA_List_Format, "P=\33c",
  238.            MUIA_Listview_List, FloattextObject,
  239.              MUIA_Frame, MUIV_Frame_None,
  240.              MUIA_Floattext_Text, guistuff_CenterText(text),
  241.              MUIA_Background, MUII_TextBack,
  242.              //MUIA_Font, MUIV_Font_Fixed,
  243.            End,
  244.          End);
  245.   */
  246.  
  247.   return (GroupObject,
  248.             Child, TextObject,
  249.               MUIA_Frame, MUIV_Frame_None,
  250.               MUIA_Text_Contents, text,
  251.               MUIA_Text_SetMin, TRUE,
  252.               MUIA_Text_PreParse, "\33c",
  253.             End,
  254.             Child, HVSpace,
  255.           End);
  256. }
  257.  
  258. /********************************************************************/
  259.  
  260. void guistuff_SetError(APTR application, long errcode)
  261. {
  262.   ((struct Application *) application)->app_Error = errcode;
  263. }
  264.  
  265. /********************************************************************/
  266.  
  267. // mx implementation for two mx buttons
  268. void __asm __saveds guistuff_MXTwoFun(register __a1 APTR *data)
  269. {
  270.   set((APTR) data[0], MUIA_Selected, TRUE);
  271.   set((APTR) data[0], MUIA_Pressed, FALSE);
  272.   set((APTR) data[1], MUIA_Selected, FALSE);
  273. }
  274.  
  275. /********************************************************************/
  276.  
  277. // mx implementation for three mx buttons
  278. void __asm __saveds guistuff_MXThreeFun(register __a1 APTR *data)
  279. {
  280.   set((APTR) data[0], MUIA_Selected, TRUE);
  281.   set((APTR) data[0], MUIA_Pressed, FALSE);
  282.   set((APTR) data[1], MUIA_Selected, FALSE);
  283.   set((APTR) data[2], MUIA_Selected, FALSE);
  284. }
  285.  
  286. /********************************************************************/
  287.  
  288. // mx implementation for four mx buttons
  289. void __asm __saveds guistuff_MXFourFun(register __a1 APTR *data)
  290. {
  291.   set((APTR) data[0], MUIA_Selected, TRUE);
  292.   set((APTR) data[0], MUIA_Pressed, FALSE);
  293.   set((APTR) data[1], MUIA_Selected, FALSE);
  294.   set((APTR) data[2], MUIA_Selected, FALSE);
  295.   set((APTR) data[3], MUIA_Selected, FALSE);
  296. }
  297.  
  298. /********************************************************************/
  299.  
  300. // peek anything to anywhere :)
  301. void __asm __saveds guistuff_SetValFun(register __a1 APTR *data)
  302. {
  303.   *((APTR *) data[0]) = (APTR) data[1];
  304. }
  305.  
  306. /********************************************************************/
  307.  
  308. // just refresh the gui
  309. void guistuff_Refresh(APTR application)
  310. {
  311.   #ifdef DEBUG
  312.   DEBUG_MAKRO
  313.   #endif
  314.  
  315.   DoMethod(((struct Application *) application)->app_Application, MUIM_Application_InputBuffered);
  316. }
  317.  
  318. /********************************************************************/
  319.  
  320. // build a new path
  321. char *guistuff_BuildPath(char *path, char *file)
  322. {
  323.   long newpathlen = strlen(path) + strlen(file) + 5;
  324.   char *newpath;
  325.  
  326.   if (newpath = sav_AllocVec(newpathlen, MEMF_ANY))
  327.   {
  328.     strcpy(newpath, path);
  329.     if (DOSFALSE == AddPart(newpath, file, newpathlen)) { sav_FreeVec(newpath); newpath = NULL; }
  330.   }
  331.  
  332.   return(newpath);
  333. }
  334.  
  335. /********************************************************************/
  336.  
  337. static void __asm __saveds gui_BTMKDirOpenFun(register __a2 APTR, register __a1 APTR *);
  338. static void __asm __saveds gui_BTMKDirDrivesFun(register __a2 APTR, register __a1 APTR *);
  339. static void __asm __saveds gui_BTParentFun(register __a2 APTR, register __a1 APTR *);
  340. static void __asm __saveds gui_LVDirlistSelectFun(register __a2 APTR, register __a1 APTR *);
  341. static void __asm __saveds gui_LVDriveslistSelectFun(register __a2 APTR, register __a1 APTR *);
  342. static void __asm __saveds gui_STNewDirFun(register __a2 APTR, register __a1 APTR *);
  343.  
  344. static const struct Hook gui_bt_parent_hook = { { NULL, NULL }, (VOID *) gui_BTParentFun, NULL, NULL };
  345. static const struct Hook gui_lv_dirlistselect_hook = { { NULL, NULL }, (VOID *) gui_LVDirlistSelectFun, NULL, NULL };
  346. static const struct Hook gui_lv_driveslistselect_hook = { { NULL, NULL }, (VOID *) gui_LVDriveslistSelectFun, NULL, NULL };
  347. static const struct Hook gui_bt_mkdiropen_hook = { { NULL, NULL }, (VOID *) gui_BTMKDirOpenFun, NULL, NULL };
  348. static const struct Hook gui_bt_mkdirdrives_hook = { { NULL, NULL }, (VOID *) gui_BTMKDirDrivesFun, NULL, NULL };
  349. static const struct Hook gui_st_newdir_hook = { { NULL, NULL }, (VOID *) gui_STNewDirFun, NULL, NULL };
  350.  
  351. // since ASKFILE and ASKDIR do nearly the same, we can put them together into
  352. // only one function
  353. char *guistuff_AskFile_AskDir(APTR application, struct FunctionEnvironment *localenv, BOOL askdir)
  354. {
  355.   #ifdef DEBUG
  356.   DEBUG_MAKRO
  357.   #endif
  358.  
  359.   {
  360.     struct Application *app = (struct Application *) application;
  361.  
  362.     char *path, *newpath,
  363.          *file;
  364.  
  365.     char file_cpy[128], dir_cpy[256];
  366.  
  367.     // error or default: return the empty string ""
  368.     char *retval = app->app_Texts[EMPTY];
  369.  
  370.     APTR ASKDIR_ST_Path, ASKDIR_ST_File, ASKDIR_LV_Dirlist;
  371.  
  372.     APTR BT_parent, BT_drives, BT_mkdir,
  373.          LV_DrivesLV, LV_DirLV, LV_Driveslist,
  374.          GR_buttons,
  375.          obj;
  376.  
  377.     // extract path and file for better handling with mui
  378.     strncpy((char *) &dir_cpy, (char *) localenv->fe_Default, 255);
  379.     if (askdir) { file_cpy[0] = 0; }
  380.     else
  381.     {
  382.       sav_PutChar(PathPart((STRPTR) &dir_cpy), 0L);
  383.       strncpy((char *) &file_cpy, (char *) FilePart((char *) localenv->fe_Default), 128);
  384.     }
  385.  
  386.     // create the gui object
  387.     obj = GroupObject,
  388.             Child, TextObject,
  389.               MUIA_Frame, MUIV_Frame_None,
  390.               MUIA_Text_Contents, localenv->fe_Prompt,
  391.               MUIA_Text_SetMin, TRUE,
  392.               MUIA_Text_PreParse, "\33c",
  393.             End,
  394.             Child, LV_DirLV = ListviewObject,
  395.               MUIA_Listview_List, app->app_MkdirRelatedDirlist = ASKDIR_LV_Dirlist = DirlistObject,
  396.                 MUIA_Dirlist_DrawersOnly, askdir,
  397.                 MUIA_Dirlist_Directory, &dir_cpy,
  398.               End,
  399.               MUIA_Background, MUII_ListBack,
  400.               MUIA_Frame, MUIV_Frame_InputList,
  401.               MUIA_ShowMe, !localenv->fe_Disk,
  402.             End,
  403.             Child, LV_DrivesLV = ListviewObject,
  404.               MUIA_Background, MUII_ListBack,
  405.               MUIA_Frame, MUIV_Frame_InputList,
  406.               MUIA_Listview_List, LV_Driveslist = VolumelistObject,
  407.                 //
  408.               End,
  409.               MUIA_ShowMe, localenv->fe_Disk,
  410.             End,
  411.             Child, ASKDIR_ST_Path = StringObject,
  412.               MUIA_Frame, MUIV_Frame_String,
  413.               MUIA_String_Format, MUIV_String_Format_Center,
  414.               MUIA_String_Contents, &dir_cpy,
  415.               MUIA_String_MaxLen, 128,
  416.               MUIA_ShowMe, !localenv->fe_Disk,
  417.             End,
  418.             Child, ASKDIR_ST_File = StringObject,
  419.               MUIA_Frame, MUIV_Frame_String,
  420.               MUIA_String_Format, MUIV_String_Format_Center,
  421.               MUIA_String_Contents, &file_cpy,
  422.               MUIA_String_MaxLen, 128,
  423.               MUIA_ShowMe, !askdir,
  424.             End,
  425.             Child, GR_buttons = GroupObject,
  426.               MUIA_Group_Horiz, TRUE,
  427.               Child, BT_parent = SimpleButton(app->app_Texts[BUTTON_PARENT]),
  428.               Child, BT_drives = SimpleButton(app->app_Texts[BUTTON_DRIVES]),
  429.               Child, BT_mkdir = SimpleButton(app->app_Texts[BUTTON_MKDIR]),
  430.             End,
  431.           End;
  432.  
  433.     if (obj)
  434.     {
  435.       // join the string gadget and the listview, so they notify each other
  436.       DoMethod(ASKDIR_ST_Path, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
  437.                ASKDIR_LV_Dirlist, 3, MUIM_Set, MUIA_Dirlist_Directory, MUIV_TriggerValue);
  438.       DoMethod(ASKDIR_LV_Dirlist, MUIM_Notify, MUIA_Dirlist_Directory, MUIV_EveryTime,
  439.                ASKDIR_ST_Path, 3, MUIM_Set, MUIA_String_Contents, MUIV_TriggerValue);
  440.  
  441.       // the active lv-entry changed
  442.       DoMethod(ASKDIR_LV_Dirlist, MUIM_Notify, MUIA_List_Active, MUIV_EveryTime,
  443.                MUIV_Notify_Self, 5, MUIM_CallHook, &gui_lv_dirlistselect_hook,
  444.                ASKDIR_ST_Path, ASKDIR_ST_File, ASKDIR_LV_Dirlist);
  445.  
  446.       // the user entered a new directory, so we have to update the listview
  447.       DoMethod(ASKDIR_ST_Path, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
  448.                MUIV_Notify_Self, 5, MUIM_CallHook, &gui_st_newdir_hook, ASKDIR_ST_Path, ASKDIR_ST_File, ASKDIR_LV_Dirlist);
  449.  
  450.       // the user selected a new volume from the volumes list
  451.       DoMethod(LV_Driveslist, MUIM_Notify, MUIA_List_Active, MUIV_EveryTime,
  452.                MUIV_Notify_Self, 10, MUIM_CallHook, &gui_lv_driveslistselect_hook,
  453.                obj, LV_DrivesLV, LV_DirLV, ASKDIR_ST_Path, ASKDIR_ST_File, GR_buttons, ASKDIR_LV_Dirlist, askdir);
  454.  
  455.       // we have to create a new directory; note, that we created the "makedir" stuff at the beginning
  456.       DoMethod(BT_mkdir, MUIM_Notify, MUIA_Pressed, FALSE,
  457.                MUIV_Notify_Self, 4, MUIM_CallHook, &gui_bt_mkdiropen_hook, ASKDIR_ST_Path, app);
  458.  
  459.       //
  460.       DoMethod(BT_drives, MUIM_Notify, MUIA_Pressed, FALSE,
  461.                MUIV_Notify_Self, 8, MUIM_CallHook, &gui_bt_mkdirdrives_hook, obj, LV_DrivesLV, LV_DirLV, ASKDIR_ST_Path, ASKDIR_ST_File, GR_buttons);
  462.  
  463.       // move to parent dir, if one presses "Parent"
  464.       DoMethod(BT_parent, MUIM_Notify, MUIA_Pressed, FALSE,
  465.                MUIV_Notify_Self, 5, MUIM_CallHook, &gui_bt_parent_hook, ASKDIR_ST_Path, ASKDIR_ST_File, ASKDIR_LV_Dirlist);
  466.  
  467.       // if there exists a BACK function, we have to change the cancel-button into a
  468.       // back-button; or, if the swing-mode is off, we have to care for the possibly
  469.       // modified cancel-button-text
  470.       if (localenv->fe_Back)         { guistuff_SetBackButton(app, TRUE); }
  471.       else if (!app->app_SWING_Mode) { igui_NameCancel(app, (char *) app->app_GlobalEnv[GENV_ABORT_BUTTON]); }
  472.  
  473.       // set the help texts
  474.       igui_SetHelp(app, (char *) localenv->fe_Help);
  475.  
  476.       //
  477.       if (guistuff_NewContent(app, obj))
  478.       {
  479.         //
  480.         igui_WaitApp(app);
  481.         if (!igui_QuitApp(app))
  482.         {
  483.           // an now get a copy of the selected file-name or just the path-name
  484.           GetAttr(MUIA_String_Contents, ASKDIR_ST_Path, (ULONG *) &path);
  485.           GetAttr(MUIA_String_Contents, ASKDIR_ST_File, (ULONG *) &file);
  486.  
  487.           //
  488.           if (askdir)
  489.           {
  490.             newpath = sav_DupString2(path);
  491.             if (newpath) { retval = newpath; }
  492.             else         { /* OUT OF MEMORY */ guistuff_SetError(app, GUIERROR_OUT_OF_MEMORY); }
  493.           }
  494.  
  495.           //
  496.           else
  497.           {
  498.             retval = guistuff_BuildPath(path, file);
  499.             if (!retval) { /* OUT OF MEMORY */ retval = app->app_Texts[EMPTY]; }
  500.           }
  501.         }
  502.         else { /* user wants to quit */ }
  503.       }
  504.       else { /* NO GUI OBJECT */ guistuff_SetError(app, GUIERROR_NO_GUI_OBJECT); }
  505.  
  506.       if (localenv->fe_Back) { guistuff_SetBackButton(app, FALSE); }
  507.     }
  508.     else { /* NO GUI OBJECT */ guistuff_SetError(app, GUIERROR_NO_GUI_OBJECT); }
  509.  
  510.     //
  511.     igui_EmptyPanel(app);
  512.     guistuff_SleepApp(app);
  513.     return(retval);
  514.   }
  515. }
  516.  
  517. static void __asm __saveds gui_BTParentFun(register __a2 APTR obj, register __a1 APTR *data)
  518. {
  519.   // move to the parent directory
  520.  
  521.   // data[0] - string gadget "Directory"
  522.   // data[1] - string gadget "File"
  523.   // data[2] - Dirlist object
  524.  
  525.   BPTR lock, parent;
  526.  
  527.   char *str,
  528.        path[128];
  529.  
  530.   GetAttr(MUIA_String_Contents, (APTR) data[0], (ULONG *) &str);
  531.   if (lock = Lock(str, SHARED_LOCK))
  532.   {
  533.     if (parent = ParentDir(lock))
  534.     {
  535.       if (DOSFALSE != NameFromLock(parent, (char *) &path, 127))
  536.       {
  537.         SetAttrs(data[1], MUIA_String_Contents, NULL, TAG_DONE);
  538.         SetAttrs(data[2], MUIA_Dirlist_Directory, &path, TAG_DONE);
  539.       }
  540.       else { /* path[128] may be too short */ DisplayBeep(NULL); }
  541.  
  542.       UnLock(parent);
  543.     }
  544.     else { /* unable to move to parent */ DisplayBeep(NULL); }
  545.  
  546.     UnLock(lock);
  547.   }
  548.   else { /* no lock */ DisplayBeep(NULL); }
  549. }
  550.  
  551. static void __asm __saveds gui_LVDirlistSelectFun(register __a2 APTR obj, register __a1 APTR *data)
  552. {
  553.   // the active item of the dirlist changed; if the new ective one is
  554.   // a file, then copy the name to the string gadget, otherweise
  555.   // selected item is a dir) change to the new directory
  556.  
  557.   // data[0] - string gadget "Directory"
  558.   // data[1] - string gadget "File"
  559.   // data[2] - Dirlist object
  560.  
  561.   long active, path;
  562.   struct FileInfoBlock *fib;
  563.   char str_copy[256];
  564.  
  565.   GetAttr(MUIA_List_Active, obj, (ULONG *) &active);
  566.   if (active >= 0)
  567.   {
  568.     DoMethod(obj, MUIM_List_GetEntry, active, &fib);
  569.  
  570.     // selected item is a directory
  571.     if (fib->fib_DirEntryType > 0)
  572.     {
  573.       GetAttr(MUIA_String_Contents, data[0], (ULONG *) &path);
  574.  
  575.       strncpy((char *) &str_copy, (char *) path, 255);
  576.       AddPart((STRPTR) &str_copy, (STRPTR) &(fib->fib_FileName), 255);
  577.  
  578.       SetAttrs(data[1], MUIA_String_Contents, NULL, TAG_DONE);
  579.       SetAttrs(data[2], MUIA_Dirlist_Directory, &str_copy, TAG_DONE);
  580.     }
  581.  
  582.     // the selected item is a file
  583.     else if (fib->fib_DirEntryType < 0)
  584.     {
  585.       SetAttrs(data[1], MUIA_String_Contents, &(fib->fib_FileName), TAG_DONE);
  586.     }
  587.   }
  588. }
  589.  
  590. static void __asm __saveds gui_LVDriveslistSelectFun(register __a2 APTR obj, register __a1 APTR *data)
  591. {
  592.   // the user selected an entry from the drives list -> move to the
  593.   // new directory
  594.  
  595.   // data[0] - ASKFILE/ASKDIR's root object
  596.   // data[1] - listview for the Volumelist
  597.   // data[2] - listview for the Dirlist
  598.   // data[3] - string gadget "Directory"
  599.   // data[4] - string gadget "File"
  600.   // data[5] - the 3 buttons
  601.   // data[6] - Dirlist object itself
  602.   // data[7] - the flag, if this is called by ASKDIR or ASKFILE
  603.  
  604.   long active;
  605.   char *path;
  606.  
  607.   GetAttr(MUIA_List_Active, obj, (ULONG *) &active);
  608.   if (active >= 0)
  609.   {
  610.     DoMethod(obj, MUIM_List_GetEntry, active, &path);
  611.     if (DoMethod((APTR) data[0], MUIM_Group_InitChange))
  612.     {
  613.       set((APTR) data[5], MUIA_ShowMe, TRUE);
  614.       set((APTR) data[4], MUIA_ShowMe, !data[7]);
  615.       set((APTR) data[3], MUIA_ShowMe, TRUE);
  616.       set((APTR) data[2], MUIA_ShowMe, TRUE);
  617.       set((APTR) data[1], MUIA_ShowMe, FALSE);
  618.       DoMethod((APTR) data[0], MUIM_Group_ExitChange);
  619.     }
  620.     SetAttrs(data[4], MUIA_String_Contents, NULL, TAG_DONE);
  621.     SetAttrs(data[6], MUIA_Dirlist_Directory, path, TAG_DONE);
  622.   }
  623. }
  624.  
  625. static void __asm __saveds gui_BTMKDirOpenFun(register __a2 APTR obj, register __a1 APTR *data)
  626. {
  627.   // open the "MakeDir" window
  628.  
  629.   // data[0] - string gadget "Directory"
  630.   // data[1] - pointer to the Application structure
  631.  
  632.   struct Application *app = (struct Application *) data[1];
  633.   long path;
  634.  
  635.   GetAttr(MUIA_String_Contents, (APTR) data[0], (ULONG *) &path);
  636.  
  637.   set(app->app_MkdirName, MUIA_String_Contents, path);
  638.   set(app->app_MkdirWindow, MUIA_Window_Open, TRUE);
  639.   set(app->app_MainWindow, MUIA_Window_Sleep, TRUE);
  640. }
  641.  
  642. static void __asm __saveds gui_BTMKDirDrivesFun(register __a2 APTR obj, register __a1 APTR *data)
  643. {
  644.   // change the gui to the Volumelist, thus, we have to show some
  645.   // objects and "un-show" some others!
  646.  
  647.   if (DoMethod((APTR) data[0], MUIM_Group_InitChange))
  648.   {
  649.     set((APTR) data[5], MUIA_ShowMe, FALSE);
  650.     set((APTR) data[4], MUIA_ShowMe, FALSE);
  651.     set((APTR) data[3], MUIA_ShowMe, FALSE);
  652.     set((APTR) data[2], MUIA_ShowMe, FALSE);
  653.     set((APTR) data[1], MUIA_ShowMe, TRUE);
  654.     DoMethod((APTR) data[0], MUIM_Group_ExitChange);
  655.   }
  656. }
  657.  
  658. static void __asm __saveds gui_STNewDirFun(register __a2 APTR obj, register __a1 APTR *data)
  659. {
  660.   // the user entered a new path into the string gadget ->
  661.   // check if this path is valid (if not, use "SYS:") and set
  662.   // the new path to the listview
  663.  
  664.   // data[0] - string gadget "Directory"
  665.   // data[1] - string gadget "File"
  666.   // data[2] - dirlist gadget
  667.  
  668.   char *newpath;
  669.   GetAttr(MUIA_String_Contents, (APTR) data[0], (ULONG *) &newpath);
  670.  
  671.   // if the entered path does not exist, use SYS: instead
  672.   if (!sav_DirExists(newpath)) { newpath = "SYS:"; SetAttrs((APTR) data[0], MUIA_String_Contents, newpath, TAG_DONE); }
  673.  
  674.   SetAttrs((APTR) data[1], MUIA_String_Contents, NULL, TAG_DONE);
  675.   SetAttrs((APTR) data[2], MUIA_Dirlist_Directory, newpath, TAG_DONE);
  676. }
  677.  
  678.